package com.ftg.learn.springboot.brand.controller;

import com.ftg.learn.springboot.brand.pojo.brand;
import com.ftg.learn.springboot.brand.service.brandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RequestMapping("brand")
@RestController

public class brandController {

	@Autowired
	brandService bs;

	@GetMapping("/PV")
	public Map<String, Object> showPV(){

		Map<String, Object> Map = new HashMap<>();
		String list = bs.showPV();
		Map.put("top",list);
		return Map;

	}

	@GetMapping("/countall")
	public int countall(){

		return bs.countall();
	}

	@GetMapping("showall")
	public List<brand> showall() {

		return bs.showall();
	}

	@GetMapping("/show/{bcategory}")
	public Map<String, Object> show(@PathVariable String bcategory){

		Map<String, Object> map = new HashMap<>();
		List<brand> list = bs.show(bcategory);
		map.put("data",list);
		map.put("code", 0);

		return map;

	}
	//热度前四
	@GetMapping("/showByHeat/{bcategory}")
	public Map<String, Object> findFirstHeat(@PathVariable String bcategory){

		Map<String, Object> heatMap = new HashMap<>();
		brand list1 = bs.findFirstHeat(bcategory);
		brand list2 = bs.findSecondHeat(bcategory);
	    brand list3 = bs.findThirdHead(bcategory);
		brand list4 = bs.findFourthHead(bcategory);
		heatMap.put("top1",list1);
		heatMap.put("top2",list2);
		heatMap.put("top3",list3);
		heatMap.put("top4",list4);
		heatMap.put("code", 0);
		heatMap.put("msg", "到哪里?");
		heatMap.put("list",bs.showall());
		return heatMap;

	}

	@GetMapping("/toompinpai")
	public ModelAndView LoginGet(String name){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("index");
		return modelAndView;
	}

	@GetMapping("/showByHeat")
	public Map<String, Object> showByHeat(){

		Map<String, Object> Map = new HashMap<>();
		List<brand> list = bs.showByHeat();
		Map.put("top",list);
		Map.put("code", 0);
		return Map;

	}

	@GetMapping("/showByEnjoy")
	public Map<String, Object> showByEnjoy(){

		Map<String, Object> Map = new HashMap<>();
		List<brand> list = bs.showByEnjoy();
		Map.put("top",list);
		Map.put("code", 0);
		return Map;

	}

	@PostMapping("/dianzan/{id}")
	public int dianzan1(@PathVariable String id){

		return bs.dianzan(id);
	}

	@PostMapping("/dianzan")
	public int dianzan2(String bid){

			return bs.dianzan(bid);
	}	@PostMapping("/quxiaodianzan/{id}")
	public int quxiaodianzan1(@PathVariable String id){

		return bs.quxiaodianzan(id);
	}

	@PostMapping("/quxiaodianzan")
	public int quxiaodianzan2(String bid){

			return bs.quxiaodianzan(bid);
	}

	@GetMapping("/showExcellent")
	public Map<String, Object> showExcellent(){

		Map<String, Object> Map = new HashMap<>();
		List<brand> list = bs.showExcellent();
		Map.put("top",list);
		Map.put("code", 0);
		return Map;

	}

}
